import { get, post } from './request'
import { getURIParam } from '../utils/browser'

/**
 * 获取json配置
 * @param {*} mdId
 * @returns
 */
export async function getSceneConfig() {
  // const  data  = await get(`./models/effectLight.json`,undefined) || {};
  const data = await post(`/v1/park/getWebgl?serial=${getURIParam('serial')}`)
  return data
}

/**
 * 获取场景中的树结构
 * @param {*} mdId
 * @returns
 */
export async function getInstanceTrees() {
  const data = (await get(`./data/environment.json`, undefined)) || {}
  return data
}

/**
 * 获取楼层下的设备
 * @returns 
 */
export async function getFloorChilds(id) {
  const data = (await get(`/v1/park/getWebParkCabinet?id=${id}`, undefined)) || {}
  return data
}


/**
 * 获取场景中的树结构
 * @param {*} mdId
 * @returns
 */
export async function getTravellines() {
  const data = (await get(`/v1/travelLine/getTravelLine/${getURIParam('id')}`)) || {}
  return data
}

/**
 * 获取所有的场景数据
 * @param {*} mdId
 * @returns
 */
export async function getCampusData() {
  // const  data  = await get(`./data/campus.json`,undefined) || {};
  const data = await get(`/v1/park/getWebParkCampus?serial=${getURIParam('serial')}`)
  return data.data
}

export function getTrankLine(id) {
  return []
}

export async function requestAPI(data) {
  return await requestByUrl(data)
}

//根据选择的3d接口发送请求
export function requestByUrl(obj) {
  if (obj.requestMethod === 'GET') {
    let params = KVToRecordable(obj.parameter)
    return get(obj.path, params)
  } else if (obj.requestMethod === 'POST') {
    let data = KVToRecordable(obj.parameter)
    return post(obj.path, data)
  }
}

function KVToRecordable(values) {
  const data = {}
  for (const item of values) {
    for (let keyi in item) {
      data[keyi] = item[keyi]
    }
  }
  return data
}

/**
 * 单点登录
 * @param {*} data
 * @returns
 */
export async function signLogin(data) {
  const res = (await post(`/v1/SignLogin`, data)) || {}
  return res
}
